package com.ecas.code.generator.service.chain;

import com.ecas.code.generator.dto.ParamterDTO;
import com.ecas.code.generator.util.CodeGeneratorFeemarkerUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.Properties;
import java.util.zip.ZipOutputStream;

@Slf4j
public class HtmlGenerator extends GeneratorHandler {


    @Override
    public void handleGenerate(ParamterDTO paramterDTO) {
        if (paramterDTO.isCreateHtml() == true) {
            this.process(paramterDTO);
        }
        super.handleGenerate(paramterDTO);


    }

    @Override
    public void process(ParamterDTO paramterDTO) {
        Properties properties = super.getProperties();
        ZipOutputStream zipOutputStream = super.getZipOutputStream();
        Map<String, Object> templateDataMap = super.getTemplateData();
        String fileName = templateDataMap.get("moduleName").toString() + templateDataMap.get("className");
        properties.put("fileName", fileName);
        properties.put("stuffx",".html");
        CodeGeneratorFeemarkerUtil.codeGenerator(properties, templateDataMap, zipOutputStream);
        log.info("html processs table:{}", paramterDTO.getTableName());
    }
}
